package jay.home.bet.web.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jay.home.bet.domain.Event;
import jay.home.bet.misc.Util;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class NextEventAction extends BaseAction {

	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws Exception
	{
		request.getParameterMap();
		
		Event event = new Event();
		
		String compId = request.getParameter("compId");
		
		if ( compId == null || compId.equals("") )
		{
			SubmitEventAction submitEventAction = new SubmitEventAction();
			
			//event = submitEventAction.submitEvent( request ,this.getBasicService() , this.getOddsService());
			
			event.getComp().setHome( getBasicService().getTeam( event.getComp().getHome().getId()) );
			event.getComp().setRoad( getBasicService().getTeam( event.getComp().getRoad().getId()) );
			event.setId(Util.uuid());
		}
		else
		{
			
			event = getOddsService().getEventByComp(compId);
			event.setId(Util.uuid());			
			
			event.getDaxiao().setHome(Util.toDouble(request.getParameter("daxiao.home")));
			event.getDaxiao().setRoad(Util.toDouble(request.getParameter("daxiao.road")));
			event.getDaxiao().setPankou(request.getParameter("daxiao.pankou"));
			
			event.getRangqiu().setHome(Util.toDouble(request.getParameter("rangqiu.home")));
			event.getRangqiu().setRoad(Util.toDouble(request.getParameter("rangqiu.road")));
			event.getRangqiu().setPankou(request.getParameter("rangqiu.pankou"));
			event.getRangqiu().setWho2who(request.getParameter("rangqiu.who2who"));

		}
		getOddsService().insertEvent(event);
		
		String time = Util.date2String(event.getComp().getTime());
		
		request.setAttribute("time", time);
		request.setAttribute("event", event);
		return mapping.findForward("SUCCESS");
	}
}
